var TicketsList = {};
var Ticket = {
    id: 0,
    id_excase: 0
}
var STATUS = {
    0 : 'New',
    1 : 'Active',
    2 : 'Resolved',
    3 : 'Deleted',
    4 : 'Active'
};
var Dicts = {};
var excases = [];
function initApplication() {
    //init
	$.ajax({
		url:baselocation+"/tickets/get_excases_ticket",
		type: 'get',
		dataType: 'json',
		success:function(result){
			excases=result.excases;
	}
});
 //   HidePaginator();
	return;
    ClearMiddleTicketsList();
}
function hideAll() {
    $("#ticket_list").html('');
    HidePaginator();
    ClearMiddleTicketsList();
}

function ShowLeftTicketsList(data) {
}
 function show_tickets(eo,el){
			 $(".ticket_title").removeClass("active");
			 $(eo).parents(".ticket_title").addClass("active");
			 $(".ticketsBox").css("display","none");
			 $("."+el).css("display","block");
			 
			
			}

function ClearMiddleTicketsList() {
    $('#ticket_view_info').html('');
    $('#ticket_view_status_view').html('');
    $('#ticket_view_comments').html('');
    $("#ticket_view_status").hide();
    $("#ticket_view_status_edit").hide();
    $("#ticketStatusSave").hide();
    $("#ticketStatusCancel").hide();
    $("#add_comment_link").hide();
    $("#ticket_closed_text").html('');
    HideAddMessageForm();
}
function ShowAddMessageForm() {
    $('#form_reply').show();
    createUploader(document.getElementById('add_ticket_comment_files'));
}
function HideAddMessageForm() {
    $('#form_reply textarea').val('');
    $('#form_reply').hide();
}
function ShowAddTicketPrefForm() {
	ShowAddTicketForm();
}
// AddTicketForm
function ShowAddTicketForm() {
    createUploader(document.getElementById('add_ticket_files'));
    if ($("#excases")[0].options.length == 0) {
        $('<option value="" style="color: gray;">-- ' + getTranslation('tickets_select_excase') + ' --</option>').appendTo("#excases");
        for (var i = 0; i < excases.length; i++) {
           
            $('<option value="' + excases[i].id + '"> - - ' + getTranslation(excases[i].excases_name) + '</option>').appendTo("#excases");
        }
    }
    $('#ticket_add').show();
    $('#ticket_add').dialog({
        width: 750,
        title: getTranslation(getTranslation('Create ticket')),
        buttons: '#ticket_add_buttons',
        modal: true
    });
}
function HideAddTicketForm() {
    $('#ticket_add').dialog('close');
    $('#ticket_new_title').val('');
    $('#ticket_add textarea').val('');
    $('#newUpload3').empty();
    $('.qq-upload-list').empty();
    $('#ticket_add input[name=t]').removeClass('error');
	$('#ticket_add textarea[name=m]').removeClass('error');
}
ticketSaved = false;
//create
function CreateTicket() {

if ($('#ticket_add input[name=t]').val().trim() == '' || $('#ticket_add textarea[name=m]').val().trim() == '') {
	if ($('#ticket_add input[name=t]').val().trim() == '')
		$('#ticket_add input[name=t]').addClass('error');
	if ($('#ticket_add textarea[name=m]').val().trim() == '')
		$('#ticket_add textarea[name=m]').addClass('error');
	return false;
}
	/*if($("#excases").val().trim() == ''){
		showAlert(getTranslation('tickets_select_excase'));
		return false;
	}*/
	loadingShow();
	var e = $('#excases').val();
	var t = $('#ticket_new_title').val();
	var m = $('#message').val();
	var arr ="";
	$("input[name='pics']").each(function(){
		arr = arr+","+$(this).val();
	});
	 $.ajax({
			url:"/Home/Myuser/lxwmcl",
			type: 'POST',
			data:{e:e,t:t,m:m,pics:arr},
			dataType: 'json',
			success:function(result){
			if(result.status==1){
					setTimeout(function(){
						loadingHide();
						HideAddTicketForm();
						location.reload();
					},1000);
				}else{
					
				}
				 
		}
	});
	
} 
//delete
function SetStatusTicket(status) {
	 $.ajax({
			url:baselocation+"/tickets/del/",
			type: 'POST',
			data:{status:status},
			success:function(result){
				if(result.code==1){
					location.reload();
				}
				
			}
		})
}

$(document).ready(function() {
    initApplication();
});